package com.example;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.ListView;
import android.widget.MultiAutoCompleteTextView;
import android.widget.Spinner;
import android.widget.Toast;


public class MainActivity extends Activity {
	private static final String[] COUNTRIES={"Viet Nam", "Thuy Dien", "Lao", "Campuchia","Vienne"};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.listviewdemo);
        ArrayAdapter<String> adapter=new ArrayAdapter<String>(getBaseContext(), android.R.layout.simple_dropdown_item_1line,
        		COUNTRIES);
//        ArrayAdapter<String> adapter=new ArrayAdapter<String>(getBaseContext(), android.R.layout.simple_list_item_checked,
//        		COUNTRIES);        
        ListView listView=(ListView) findViewById(R.id.listView1);
        listView.setAdapter(adapter);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        	@Override
        	public void onItemClick(AdapterView<?> parent, View view,
        			int position, long id) {
        		
        		Toast.makeText(getBaseContext(), COUNTRIES[position], Toast.LENGTH_SHORT).show();
        	}
		});
        
//        setContentView(R.layout.activity_main);
//        ArrayAdapter<String> adapter=new ArrayAdapter<String>(getBaseContext(), android.R.layout.simple_dropdown_item_1line,
//        		COUNTRIES);
////        android.R. day la R cua package android nen phai co androidid. chu khong phai class r cua du an
//        //day la giao dien se hien thi (cach hien thi lay out) simple_dropdown_item_1line
//        AutoCompleteTextView autoCompleteTextView=(AutoCompleteTextView) findViewById(R.id.autoCompleteTextView1);
//        autoCompleteTextView.setAdapter(adapter);
//        MultiAutoCompleteTextView multiAutoCompleteTextView=(MultiAutoCompleteTextView) findViewById(R.id.multiAutoCompleteTextView1);
//        multiAutoCompleteTextView.setAdapter(adapter);
//        multiAutoCompleteTextView.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
//        
////        ArrayAdapter spinnerAdapter=new ArrayAdapter(getBaseContext(),R.array.countries, android.R.layout.simple_dropdown_item_1line);
////        // Truy cap vao tai nguyen, no la so R.array.countries, con muon bien thanh mang thi lam nhu cach 2
////        Spinner spinner=(Spinner) findViewById(R.id.spinner1);
////        spinner.setAdapter(spinnerAdapter);
//        
//                
////        cach 2. lay tai nguyen ve va chuyen thanh mang string
//        String [] countries=getResources().getStringArray(R.array.countries);
//        ArrayAdapter spinnerAdapter=new ArrayAdapter(getBaseContext(), android.R.layout.simple_dropdown_item_1line,
//        		countries);
//        Spinner spinner=(Spinner) findViewById(R.id.spinner1);
//        spinner.setAdapter(spinnerAdapter);
//        
//     
    
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}
